package me.shurufa.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.Bind;
import me.shurufa.R;
import me.shurufa.utils.Constants;
import me.shurufa.utils.Global;

/**
 * 点击账户跳转界面
 *
 * @FileName: me.shurufa.activities.AccountActivity.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-01-18 16:15
 */
public class AccountActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.points)
    TextView points;
    @Bind(R.id.exange_layout)
    LinearLayout exangeLayout;
    public static final int REQUEST = 100;
    public static final int RESULT = 101;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_account;
        super.onCreate(savedInstanceState);
        initUI();
    }

    private void initUI() {
//        exangeLayout.setOnClickListener(this);
        exangeLayout.setVisibility(View.GONE);

        try {
            if (Global.currentUser != null) {
                points.setText("" + Global.currentUser.credits_amount);
            } else {
                points.setText("重新登录后查看");
            }

        } catch (Exception e) {
        }
        titleTextView.setText(getString(R.string.account));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.exange_layout:
                Intent intent = new Intent(AccountActivity.this,ExangeActivity.class);
                startActivity(intent);
                break;
        }
    }

    /**
     * 在兑换页面兑换数据后 该页面的points 应该进行数据同步
     */
    @Override
    public void onEventMainThread(Intent intent) {
        super.onEventMainThread(intent);
        if (intent.getAction().equals(Constants.ACTION_POINTS_CHANGE)){
            int pointInt = intent.getIntExtra(Constants.EXTRA_POINTS,-1);
            if (pointInt != -1) {
                points.setText(String.valueOf(pointInt));
            }
        }
    }
}
